import pymysql


class MysqlUtils:
    def __init__(self):
        self.con = pymysql.connect(host='124.222.223.52', user='root', password='_MXJmxj329555407', db="Django")
        # self.con = pymysql.connect(host='localhost', user='chen', password='shizichen2003', db="Django")
        self.cur = self.con.cursor()

    def close(self):
        self.cur.close()
        self.con.close()

    # 查重
    def check_duplicate(self, nickname, text):
        query = "SELECT 1 FROM pinglun_list WHERE nickname=%s AND text=%s"
        self.cur.execute(query, (nickname, text))
        return self.cur.fetchone() is not None
